﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

/// <summary>
/// Summary description for clsCity
/// </summary>
public class clsCity
{
    InstantNaukriDataContextDataContext objInstantNaukriDataContextDataContext = new InstantNaukriDataContextDataContext();
    public clsCity()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public List<IN_TB_CITY> GetAllCities()
    {
        try
        {
            List<IN_TB_CITY> objIN_TB_CITY = new List<IN_TB_CITY>();
            objIN_TB_CITY = (from obj in objInstantNaukriDataContextDataContext.IN_TB_CITies
                             orderby obj.CITY ascending
                             select obj).ToList();
            return objIN_TB_CITY;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<IN_TB_CITY> GetAllCitiesbyState(int StateID)
    {
        try
        {
            List<IN_TB_CITY> objIN_TB_CITY = new List<IN_TB_CITY>();
            objIN_TB_CITY = (from obj in objInstantNaukriDataContextDataContext.IN_TB_CITies
                             orderby obj.CITY ascending
                             where Convert.ToInt32(obj.STATE_ID)==StateID
                             select obj).ToList();
            return objIN_TB_CITY;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<IN_TB_STATE> GetAllStates()
    {
        try
        {
            List<IN_TB_STATE> objIN_TB_STATE = new List<IN_TB_STATE>();
            objIN_TB_STATE = (from obj in objInstantNaukriDataContextDataContext.IN_TB_STATEs
                              select obj).ToList();
            return objIN_TB_STATE;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<IN_TB_COUNTRY> GetAllCountry()
    {
        try
        {
            List<IN_TB_COUNTRY> objIN_TB_COUNTRY = new List<IN_TB_COUNTRY>();
            objIN_TB_COUNTRY = (from obj in objInstantNaukriDataContextDataContext.IN_TB_COUNTRies
                              select obj).ToList();
            return objIN_TB_COUNTRY;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_COUNTRY GetCountryById(int CountryId)
    {
        try
        {
            IN_TB_COUNTRY objIN_TB_COUNTRY = new IN_TB_COUNTRY();
            objIN_TB_COUNTRY = (from obj in objInstantNaukriDataContextDataContext.IN_TB_COUNTRies
                                where obj.ID == CountryId
                              select obj).SingleOrDefault();
            return objIN_TB_COUNTRY;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_STATE GetStateById(int StateId)
    {
        try
        {
            IN_TB_STATE objIN_TB_STATE = new IN_TB_STATE();
            objIN_TB_STATE = (from obj in objInstantNaukriDataContextDataContext.IN_TB_STATEs
                              where obj.ID == StateId
                              select obj).SingleOrDefault();
            return objIN_TB_STATE;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_CITY GetCityById(int CityId)
    {
        try
        {
            IN_TB_CITY objIN_TB_CITY = new IN_TB_CITY();
            objIN_TB_CITY = (from obj in objInstantNaukriDataContextDataContext.IN_TB_CITies
                             where obj.ID == CityId
                             select obj).SingleOrDefault();
            return objIN_TB_CITY;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public void DeleteCountry(int CountryId)
    {
        try
        {
            IN_TB_COUNTRY objIN_TB_COUNTRY = new IN_TB_COUNTRY();
            objIN_TB_COUNTRY = (from obj in objInstantNaukriDataContextDataContext.IN_TB_COUNTRies
                                where obj.ID == CountryId
                             select obj).SingleOrDefault();
            if (objIN_TB_COUNTRY != null)
            {
                objInstantNaukriDataContextDataContext.IN_TB_COUNTRies.DeleteOnSubmit(objIN_TB_COUNTRY);
                objInstantNaukriDataContextDataContext.SubmitChanges();
            }

        }
        catch (Exception)
        {

            throw;
        }
    }

    public void DeleteState(int StateId)
    {
        try
        {
            IN_TB_STATE objIN_TB_STATE = new IN_TB_STATE();
            objIN_TB_STATE = (from obj in objInstantNaukriDataContextDataContext.IN_TB_STATEs
                              where obj.ID == StateId
                                select obj).SingleOrDefault();
            if (objIN_TB_STATE != null)
            {
                objInstantNaukriDataContextDataContext.IN_TB_STATEs.DeleteOnSubmit(objIN_TB_STATE);
                objInstantNaukriDataContextDataContext.SubmitChanges();
            }

        }
        catch (Exception)
        {

            throw;
        }
    }
    public int SaveCountryMst(IN_TB_COUNTRY objIN_TB_COUNTRY)
    {
        try
        {
            IN_TB_COUNTRY objIN_TB_COUNTRYD = new IN_TB_COUNTRY();
            objIN_TB_COUNTRYD = (from obj in objInstantNaukriDataContextDataContext.IN_TB_COUNTRies
                                 where obj.ID == objIN_TB_COUNTRY.ID
                              select obj).SingleOrDefault();
            if (objIN_TB_COUNTRYD != null)
            {
                objIN_TB_COUNTRYD.ID = objIN_TB_COUNTRY.ID;
                objIN_TB_COUNTRYD.COUNTRY = objIN_TB_COUNTRY.COUNTRY;

                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_COUNTRY.ID;
            }
            else
            {
                objInstantNaukriDataContextDataContext.IN_TB_COUNTRies.InsertOnSubmit(objIN_TB_COUNTRY);
                objInstantNaukriDataContextDataContext.SubmitChanges();
                int NewID = (from obj in objInstantNaukriDataContextDataContext.IN_TB_COUNTRies
                             select obj.ID).Max();
                return NewID;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }

    public void DeleteCity(int CityId)
    {
        try
        {
            IN_TB_CITY objIN_TB_CITY = new IN_TB_CITY();
            objIN_TB_CITY = (from obj in objInstantNaukriDataContextDataContext.IN_TB_CITies
                             where obj.ID == CityId
                             select obj).SingleOrDefault();
            if (objIN_TB_CITY != null)
            {
                objInstantNaukriDataContextDataContext.IN_TB_CITies.DeleteOnSubmit(objIN_TB_CITY);
                objInstantNaukriDataContextDataContext.SubmitChanges();
            }

        }
        catch (Exception)
        {

            throw;
        }
    }

    public int SaveCityMst(IN_TB_CITY objIN_TB_CITY)
    {
        try
        {
            IN_TB_CITY objIN_TB_CITYD = new IN_TB_CITY();
            objIN_TB_CITYD = (from obj in objInstantNaukriDataContextDataContext.IN_TB_CITies
                              where obj.ID == objIN_TB_CITY.ID
                              select obj).SingleOrDefault();
            if (objIN_TB_CITYD != null)
            {
                objIN_TB_CITYD.ID = objIN_TB_CITY.ID;
                objIN_TB_CITYD.CITY = objIN_TB_CITY.CITY;

                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_CITY.ID;
            }
            else
            {
                objInstantNaukriDataContextDataContext.IN_TB_CITies.InsertOnSubmit(objIN_TB_CITY);
                objInstantNaukriDataContextDataContext.SubmitChanges();
                int NewID = (from obj in objInstantNaukriDataContextDataContext.IN_TB_CITies
                             select obj.ID).Max();
                return NewID;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }

    public int SaveStateMst(IN_TB_STATE objIN_TB_STATE)
    {
        try
        {
            IN_TB_STATE objIN_TB_STATED = new IN_TB_STATE();
            objIN_TB_STATED = (from obj in objInstantNaukriDataContextDataContext.IN_TB_STATEs
                               where obj.ID == objIN_TB_STATE.ID
                              select obj).SingleOrDefault();
            if (objIN_TB_STATED != null)
            {
                objIN_TB_STATED.ID = objIN_TB_STATE.ID;
                objIN_TB_STATED.STATE = objIN_TB_STATE.STATE;
                objIN_TB_STATED.COUNTRY_ID  = objIN_TB_STATE.COUNTRY_ID;
                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_STATE.ID;
            }
            else
            {
                objInstantNaukriDataContextDataContext.IN_TB_STATEs.InsertOnSubmit(objIN_TB_STATE);
                objInstantNaukriDataContextDataContext.SubmitChanges();
                int NewID = (from obj in objInstantNaukriDataContextDataContext.IN_TB_STATEs
                             select obj.ID).Max();
                return NewID;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
}
